<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title></title>
	<script type="text/javascript">

		/*
		 * 定时器的调用是异步的
		 *
		 */

		window.onload = function () {
			var count = document.getElementById("count");
			var number = 1;

			var timer = setInterval(function () {
				count.innerHTML = number++;
				if (number == 11) {
					clearInterval(timer); // 关闭定时器
				}
			}, 1000);
		}

	</script>
</head>

<body>
	<h1 id="count"></h1>
</body>

</html>